﻿using MvvmFx.Common.ViewModels;


namespace MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels
{
    public class MasterDetailsSampleViewModel : SampleViewModel
    {
        #region instance variables

        private readonly ViewModelCollection<SampleItemViewModel> _samples;
        private SampleItemViewModel _selectedSample;

        #endregion


        #region constructors

        public MasterDetailsSampleViewModel()
        {
            // initialize instance variables
            _samples = new ViewModelCollection<SampleItemViewModel>();

            // generate sample data
            const int sampleCount = 10;
            _samples.AddRange(SampleItemViewModel.Create(sampleCount));
            _selectedSample = _samples[0];
        }

        #endregion


        #region properties

        public override string Title
        {
            get { return "Master/Details Sample"; }
        }

        public override string Description
        {
            get
            {
                return "The ListBox below is bound using the ViewModelHelper.ItemsSource "
                    + "property and the rendered ViewModels are rendered using an implicit "
                    + "DataTemplate defined in its view, overridding the DataTemplate "
                    + "defined in the parent view.\n\n"
                    + "The details view is a ContentControl that is bound to the "
                    + "selected sample item (using the ViewModelHelper.SelectedValue "
                    + "attached property) and overrides the scoped DataTemplate again "
                    + "by redefinig one specific for the details view.";
            }
        }

        public ViewModelCollection<SampleItemViewModel> Samples
        {
            get { return _samples; }
        }

        public SampleItemViewModel SelectedSample
        {
            get { return _selectedSample; }
            set
            {
                _selectedSample = value;
                OnPropertyChanged("SelectedSample");
            }
        }

        #endregion

    }  // class MasterDetailsSampleViewModel

}  // namespace MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels
